package com.fiap.activities;

import java.io.File;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.widget.ImageView;
import android.widget.TextView;

import com.fiap.model.Statistics;

public class RunSummary extends Activity {

	private TextView txtAvgSpeed;
	private TextView txtTotalDistance;
	private TextView txtTotalCal;
	private TextView txtTotalTime;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.run_summary);
		
		Statistics statistics = Statistics.getInstance();
		
		screenPrepare(statistics.getCalorias(), statistics.getTotalDistance(), statistics.getTotalTime(), statistics.getVelocidadeMedia());

		String outputDir = getApplicationContext().getCacheDir().toString();
		String outputFile = outputDir + "/user01_run_map.png";
		
		File file = new File(outputFile);
		if (file.exists()) {
			Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
			ImageView image = (ImageView) findViewById(R.id.image_map_run);
			image.setImageBitmap(bitmap);
		}		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.main_menu, menu);
		return true;
	}

	private void screenPrepare(double totalCalories, double totalDistance, double totalTime, double averageSpeed) {
		txtAvgSpeed = (TextView) findViewById(R.id.txt_avg_speed);
		txtTotalDistance = (TextView) findViewById(R.id.txt_total_distance);
		txtTotalCal = (TextView) findViewById(R.id.txt_total_cal);
		txtTotalTime = (TextView) findViewById(R.id.txt_total_time);
		
		txtAvgSpeed.setText(String.valueOf(averageSpeed));
		txtTotalDistance.setText(String.valueOf(totalDistance));
		txtTotalCal.setText(String.valueOf(totalCalories));
		txtTotalTime.setText(String.valueOf(totalTime));
	}

	private void saveRun() {
		
	}

	private void discardRun() {

	}
}
